﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <link href="css/theme/theme-red.css" rel="stylesheet" id="themeCss" />
	<link href="css/Viewers.css" rel="stylesheet" />
    <script src="js/jquery-1.10.1.min.js"></script>
    <script type="text/javascript" src="js/highcharts.js"></script>
    <script type="text/javascript" src="js/highcharts-3d.js"></script>
    <script src="js/bootstrap/bootstrap.min.js"></script>
	<script type="text/javascript" src="js/jquery-ui.min.js"></script>
	<script type="text/javascript" src="js/ViewersCommon.js"></script>
	<script type="text/javascript" src="js/common.js"></script>
	<link href="css/square/blue.css" rel="stylesheet" /> 
    <script type="text/javascript" src="js/term-explain.js"></script>
    <!--[if lte IE 9]>
<script src="/JS/bootstrap/respond.js"></script>
<![endif]-->
    <title></title>
</head>
<body>
    <img src="http://p.yibaoyun.cn/Images/wecharShare.jpg" style="width:0px; height:0px; overflow:hidden"/>
    <form id="form1" runat="server">
        <div class="container" id="viewcontainer">
            <!-- Viewer选择一览 -->
            <div class="row" id="viewerlist">
            </div>
            <!-- Viewer设置模态框 -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog modal-sm modal-lg">
                            <div class="mo-dialog-bg modal-content">
                                <div class="mo-com-bloder mo-head modal-header">
                                    <button type="button" class="fnt_title mo-bt-cancle btn btn-default" data-dismiss="modal" id="myModelCancel">取消</button>
                                    <button type="button" class="fnt_title mo-bt-save btn btn-primary" id="myModalSave">确定</button>
                                    <h4 class="mo-v-title sltm_cvr_cmpnyname modal-title" style="font-weight: normal; color: #1e1e1e;" id="myModalLabel">Modal title</h4>
                                </div>
                                <div class="modal-body" id="myModalBody">
                                </div>
                                <div class="mo-com-bloder modal-footer" id="myModelFooter">
                                    <input type="hidden" id="hidViewerId" />
									<button type="button" class="fnt_title mo-bt-cancle btn btn-default" data-dismiss="modal" id="myModelCancel2">取消</button>
                                    <button type="button" class="fnt_title mo-bt-save btn btn-primary" id="myModalSave2">确定</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 方案内容显示区域 -->
        <div class="container" id="proposalContainer">
            <div class="row">
                <div id="viewer_cont" class="col-xs-12">
                </div>
            </div>
            <br />
            <br />
            <!--推送人ID-->
            <input type="hidden" id="HidTrackClientID" />
            <!--推送人名称-->
            <input type="hidden" id="HidTrackClientName" />
			<!--推送人电话-->
            <input type="hidden" id="HidTrackClienPhone" />
             <!--代理人电话-->
            <input type="hidden" id="HidTrackAgentPhone" />
            <!--推送人性别-->
            <input type="hidden" id="HidTrackClientSex" />
            <!--代理人ID-->
            <input type="hidden" id="HidTrackAgentID" />
            <!--代理人名称-->
            <input type="hidden" id="HidTrackAgentName" />
            <!--代理人公司-->
            <input type="hidden" id="HidTrackAgentCompany" />
            <!--方案名称-->
            <input type="hidden" id="HidTrackProposalName" />
            <!--方案ID-->
            <input type="hidden" id="HidTrackProposalId" />
            <!--方案投递号-->
            <input type="hidden" id="HidTrackSendId" />
            <!--方案识别ID-->
            <input type="hidden" id="HidProjectGuid" />
            <!--投递时间-->
            <input type="hidden" id="HidSendTime" />
            <!--监控对象-->
            <input type="hidden" id="HidTrackMonitors" />
			
			<input type="hidden" id="HidProposalConfig" value='{"template":{"id":"123","name":"寿险模板","tmpltdscrpt":"<b>本计划书仅供参考，具体权利义务请以正式保险合同为准。</b>","version":"1.0","defaultparam":{"style":"123","viewerver":"1.0"},"viewers":[{"fieldName":"VCoverSubject","ordernum":"1","check":"1","required":"1","defaultparam":{}},{"fieldName":"VDesignPremium","ordernum":"2","check":"1","required":"0","defaultparam":{"sex":"1","age":"10"}},{"fieldName":"VInsureBenefit","ordernum":"3","check":"1","required":"0","defaultparam":{}},{"fieldName":"VCompositeBenefitAll","ordernum":"4","check":"1","required":"0","defaultparam":{}}]}}' />
        </div>

        <div id="HidParams" style="display: none">
            <!--代理人信息-->
            <input type="hidden" id="HidAgent" />
            <!--推送对象信息-->
            <input type="hidden" id="HidPushObj" />
            <!--模板配置信息-->
            <input type="hidden" id="HidTemplateConfig" />
            <!--方案信息-->
            <input type="hidden" id="HidProposal" />
            <!--选中的险种信息-->
            <input type="hidden" id="HidCheckProducts" />
            <!--合作公司信息-->
            <input type="hidden" id="HidCorpCompany" />
            <!--品牌信息-->
            <input type="hidden" id="HidBrand" />
            
		<input type="hidden" id="HidAttatchJson" />
		<input type="hidden" id="HidAttatchUuid" />
        </div>

        <div id="jsscript">
            <script src="js/actionProposal/Viewers-mobile.min.js"></script>
            <script src="js/validate.js"></script>
            <script src="js/actionProposal/proposal.min.js"></script>
            <script src="js/icheck.min.js"></script>
            <script type="text/javascript">
                var GLOBAL_PARAM = {
                    ProductMap: null,
                    ViewerMap: null,
                    TemplateConfig: null//模板配置对象
                }
               
                /*
                 * 设置方案的参数
                 *  AgentInfo, 代理人信息
                 *  PushInfo,投递对象信息
                 *  TempConfig,模板配置信息
                 *  ProposalInfo,方案信息
                 *  ProductInfo,产品信息
                 *  CorpCompnay,公司信息
                 *  Brand品牌信息
                 */
                function setProposalParams(AgentInfo, PushInfo, TempConfig, ProposalInfo, ProductInfo, CorpCompnay, Brand) {
                    $("#HidAgent").val(AgentInfo);
                    //手机端适应(没有推送人信息)
                    if (PushInfo == '{}') {
                        PushInfo = '{"Name":"","Phone":"","Age":25,"Prefixes":"","Email":"","Sex":1,"AndroidAccountID":""}';
                    }
                    $("#HidPushObj").val(PushInfo);
                    // 设置模板信息
                    setTemplateConfig(TempConfig);
                    // 设置监控信息
                    setMonitorsInfo(AgentInfo, PushInfo, ProposalInfo);

                    $("#HidProposal").val(ProposalInfo);
                    setChosedProductInfo(ProductInfo);
                    initProductMap(ProductInfo);
                    $("#HidCorpCompany").val(CorpCompnay);
                    $("#HidBrand").val(Brand);

                    initViewer();
                    initViewerListPageV2(GLOBAL_PARAM.ViewerMap);
                }
                /*
                 * 重新设置Viewer的选择及设定
                 */
                function resetProposal() {
                    try {
					    GLOBAL_PARAM.TemplateConfig = null;
					    GLOBAL_PARAM.TemplateConfig = convertStr2Json($("#HidTemplateConfig").val());
                        initViewer();
                        initViewerListPageV2(GLOBAL_PARAM.ViewerMap);
						
						var viewer = GLOBAL_PARAM.ViewerMap.get('VCoverSubjectXH');
                        if (viewer === undefined) {
                           $("#themeCss").attr("href", "css/theme/theme-red.css");
                        }else{
						   $("#themeCss").attr("href", "css/theme/theme-XH-openRed.css");
						}
						
                        Android.isResetSuccess(true);
                    }
                    catch (e) {
                        Android.isResetSuccess(false);
                    }
                }

				/*
                 * 设置Viewer排序
                 */
                function setViewerSort() {
				
				　　try {
                         count = 1;

                         // 透明度CSS增加
                         $(".viewerthumbnail").addClass("opacity");
                         $(".OrderNo").text("");
                         $(".settingClick").removeAttr("onclick");
                         $(".panel-body").removeAttr("onclick");

                         // 点击事件
                         $(".viewerthumbnail").click(function () {
                             $(this).removeClass("opacity");
                             if ($(this).find(".OrderNo").text() == "") {

                                 var fieldName = $(this).find("input").attr('id');
                                 var viewers = GLOBAL_PARAM.TemplateConfig.template.viewers;
                                 for (var i = 0; i < viewers.length; i++) {
                                     if (viewers[i].fieldName == fieldName) {
                                         viewers[i].ordernum = count;
                                     }
                                 }
                                 $(this).find(".OrderNo").text(count);
                                 if (count == viewers.length) {
                                     Android.isSortOver(true);
                                 }
                                 count++;
                             }
                         });
                        Android.isSortShow(true);
                    }
                    catch (e) {
                        Android.isSortShow(false);
                    }
                   
                }

                /*
                 * 重新排序Viewer
                 */
                function saveViewerSort() {
                    $("#viewerlist").html("");
                    $("#viewer_cont").html("");
                    var viewers = GLOBAL_PARAM.TemplateConfig.template.viewers;
                    viewers.sort(function (x, y) {
                        return x.ordernum - y.ordernum;
                    });
                    for (var i = 0; i < viewers.length; i++) {
                        var viewConfig = viewers[i];
                        var viewer = GLOBAL_PARAM.ViewerMap.get(viewConfig.fieldName);
                        $('<div class="col-lg-3 col-md-4 col-xs-6"></div>').append(viewer.getThumbnalHtml()).appendTo($("#viewerlist"));
                        $("#viewer_cont").append('<div class="row"><div class="col-lg-12 viewcontainer" id="viewercontainer' + viewConfig.ordernum + '"></div></div>');
                        viewer.setParent("#viewercontainer" + viewConfig.ordernum);
                    }
					
					Android.isSortShow(false);
				　　Android.isSortOver(false);
                }
				
                /*
                 * 设置方案模板
                 */
                function setTemplateConfig(tempConfig) {
                    $("#HidTemplateConfig").val(tempConfig);
                    GLOBAL_PARAM.TemplateConfig = convertStr2Json(tempConfig);
                }
                /*
                 * 设置监控信息
                 */
                function setMonitorsInfo(AgentInfo, PushInfo, ProposalInfo) {
                    var agentInfo = eval("(" + AgentInfo + ")");
                    $("#HidTrackAgentID").val(agentInfo.AgentID);
                    $("#HidTrackAgentName").val(agentInfo.AgentName);
                    $("#HidTrackAgentCompany").val(agentInfo.CompanyName);
                    $("#HidTrackAgentPhone").val(agentInfo.Phone);
					
                    var pushInfo = eval("(" + PushInfo + ")");
                    $("#HidTrackClientID").val(pushInfo.AndroidAccountID);
                    $("#HidTrackClientName").val(pushInfo.Name);
                    $("#HidTrackClientSex").val(pushInfo.Sex);
                    $("#HidTrackClienPhone").val(pushInfo.Phone);
					
                    var proposalInfo = eval("(" + ProposalInfo + ")");
                    $("#HidTrackProposalName").val(proposalInfo.Name);
                }
                /*
                 * 设置选中产品的值以及加载产品的Json数据
                 */
                function setChosedProductInfo(productInfo) {
                    $("#HidCheckProducts").val(productInfo);
                    // 清空旧的产品Json数据
                    //$(".prdctJson").remove(); //TODO 正式发布放开
                    var productList = convertStr2Json(productInfo);
                    for (var i = 0; i < productList.length; i++) {
                        var pID = productList[i].ProductID;
                        // 产品的Json不存在
                        if ($("#HidJson" + pID).length == 0) {
                            $('<input type="hidden" id="HidJson' + pID + '" class="prdctJson" />')
                                .val(Android.getProductJson("" + pID))
                                .appendTo($("#HidParams"));
                        }
                    }
                }
                /*
                 * 初始化产品Map
                 * productInfo：选中的产品的列表信息
                 */
                function initProductMap(productJsonInfo) {
                    var productList = convertStr2Json(productJsonInfo);
                    // 初始化ProductMap
                    GLOBAL_PARAM.ProductMap = null;
                    GLOBAL_PARAM.ProductMap = new Map();
                    for (var i = 0; i < productList.length; i++) {
                        var product = productList[i];
                        // 设置被保人信息
                        var pInsured = product.Insured;
                        var insuredPerson = new InsuredPerson(pInsured.Id, pInsured.Name, pInsured.Sex, pInsured.Age, pInsured.Birthday, pInsured.ProfessionID, pInsured.Relation);

                        var productObj = new InsuranceObj("HidJson" + product.ProductID, insuredPerson, "HidRateTable", product.SearchData);
                        // 设置产品在整个方案中的主键
                        productObj.setProposalProductKey(product.Index);

                        // 产品特征值设置
                        productObj.setProductFeature(product.FeatureDatas);
                        var pFeature = product.FeatureDatas;
                        $(pFeature).each(function () {
                            var fieldName = this.FieldName;
                            if (fieldName == "Coverage") {
                                productObj.setCoverage(this.Value);
                            } else if (fieldName == "Premium") {
                                productObj.setPremium(this.Value);
                            } else {
                                productObj.setControllerSelectedValueByFieldName(fieldName, this.Value);
                            }
                        });

                        setCoverageAndPremium(productObj);
                        GLOBAL_PARAM.ProductMap.put(product.Index, productObj);
                    }
                }

                /*
                 * 重新设置模板
                 * 重新初始化Viewer
                 */
                function resetTemplate(TempConfig) {
                    // 设置模板信息
                    setTemplateConfig(TempConfig);
                    initViewer();
                    initViewerListPageV2(GLOBAL_PARAM.ViewerMap);
                }
                             
                /*
                 * 方案预览
                 */
                function preview() {
                    //加载需要的基本的JS及CSS
                    var proCurrentConfig = $("#HidProposalConfig").val();
                    // 新建模式
                    if (proCurrentConfig == "" || proCurrentConfig.length == 0) {
                        alert("请先选择产品及设置Viewer");
                    } else {
                        // 初始化模板配置文件
                        GLOBAL_PARAM.TemplateConfig = convertStr2Json($("#HidTemplateConfig").val());
                        initProductMap($("#HidCheckProducts").val());
                        recoverChosedViewer();
                    }
                }
           
                /*
                 * 初始化Viewer
                 */
                function initViewer() {
                    $("#viewer_cont").html("");
                    // 获取模板Viewer的配置
                    var viewers = GLOBAL_PARAM.TemplateConfig.template.viewers;
                    GLOBAL_PARAM.ViewerMap = null;
                    GLOBAL_PARAM.ViewerMap = new Map();
                    var prdctKeys = GLOBAL_PARAM.ProductMap.keys();
					viewers.sort(function (x, y) {
                        return x.ordernum - y.ordernum;
                    });
                    for (var i = 0; i < viewers.length; i++) {
                        var viewConfig = viewers[i];
                        var viewer = eval("new " + viewConfig.fieldName + "()");
                        if (viewConfig.defaultparam != null) {
                            viewer.setDefaultParam(viewConfig.defaultparam);
                        }
                        if (viewConfig.fromJson != null) {
                            viewer.fromJson(viewConfig.fromJson);
                        }
                        $("#viewer_cont").append('<div class="row"><div class="col-lg-12 viewcontainer" id="viewercontainer' + viewConfig.ordernum + '"></div></div>');
                        viewer.setParent("#viewercontainer" + viewConfig.ordernum);
                        viewer.setID("viewercontainer" + viewConfig.ordernum);
                        // 设置产品的选中状态
                        viewer.checkStatus = viewConfig.check;
                        viewer.required = viewConfig.required;
                        // 给Viewer设置产品信息
                        for (var j = 0; j < prdctKeys.length; j++) {
                            viewer.addProduct(GLOBAL_PARAM.ProductMap.get(prdctKeys[j]));
                        }
                        GLOBAL_PARAM.ViewerMap.put(viewConfig.fieldName, viewer);
                    }
                }
                /*
                 * 初始化Viewer一览画面
                 */
                function initViewerListPage(viewerMap) {
                    $("#viewerlist").html("");
                    var viewerKeys = viewerMap.keys();
                    for (var i = 0; i < viewerKeys.length; i++) {
                        var viewer = viewerMap.get(viewerKeys[i]);
                        $('<div class="col-lg-3 col-md-4 col-xs-6"></div>').append(viewer.getThumbnalHtml()).appendTo($("#viewerlist"));
                    }
                    $("#myModalSave,#myModalSave2").unbind("click");
                    $("#myModalSave,#myModalSave2").click(function () {
                        GLOBAL_PARAM.ViewerMap.get($("#hidViewerId").val()).doAfterParam();
                        $('#myModal').modal('hide');
                    });
                    
                    $("#myModelCancel,#myModelCancel2").unbind("click");
                    $("#myModelCancel,#myModelCancel2").click(function () {
                    });
                }
				
				/*
                 * 初始化Viewer一览画面
                 */
                function initViewerListPageV2(viewerMap) {
                    $("#viewerlist").html("");
                    var viewerKeys = viewerMap.keys();
                    for (var i = 0; i < viewerKeys.length; i++) {
                        var viewer = viewerMap.get(viewerKeys[i]);
                        var $Panel;
                        if (viewer.fieldName == "VDesignPremiumV2" || viewer.fieldName == "VInsureBenefitV2") {
                            $Panel = $('<div class="panel panel-set" style="display:none;"></div>');
                        } else {
                            $Panel = $('<div class="panel panel-set"></div>');
                        }
                        strCollapsed = " collapsed";
                        var $PanelHead = $('<div class="panel-heading ' + strCollapsed + '" role="tab" style="position:relative" id="head' + viewer.fieldName + '" data-toggle="collapse" data-parent="#viewerlist" href="#collapse' + viewer.fieldName + '" aria-expanded="true" aria-controls="collapse' + viewer.fieldName + '"></div>');


                        var checked = viewer.checkStatus == 0 ? "" : " checked ";
                        var readonly = viewer.required == 0 ? "" : ';visibility:hidden';
                        $('<h4 class="panel-title fnt_lg" style="color:#1e1e1e" ></h4>')
                            .append('<img style="width:24px;height:24px;margin-right:5px" src=' + viewer.thumbnail.bgImg + '></img>')
                            .append('<div style="position:absolute;top:5px;right:15px;' + readonly + '"><input type="checkbox"  class="form-control checkbox-inline viewcheckmark iCheckboxNoEvent" id="' + viewer.fieldName + '"' + checked + '"></div>&nbsp;&nbsp;' + viewer.cName + "&nbsp;&nbsp;&nbsp;&nbsp;")
                            //.append('<div class="clear:both"></div>')
                        .append('<span class="glyphicon glyphicon-menu-up"></span>').appendTo($PanelHead);
                        $Panel.append($PanelHead);
                        var strShowContent = "";
                        
                        var $PanelBody = $('<div id="collapse' + viewer.fieldName + '" class="panel-collapse collapse' + strShowContent + '" role="tabpanel" aria-labelledby="head' + viewer.fieldName + '"><div class="panel-body" style="border-bottom:1px solid #dcdcdc">' +
                            viewer.doInitParam()
                            + '</div></div>');
                        $Panel.append($PanelBody);
                        $("#viewerlist").append($Panel);
                        viewer.doInitEvent();
                    }
					//checkbox初始化
                    $('.iCheckbox').iCheck({
                        checkboxClass: 'icheckbox_square-blue'              
                    });
                    $('.iCheckboxNoEvent').iCheck({
                        checkboxClass: 'icheckbox_square-blue'
                  
                    });		
                    $('.viewcheckmark').click(function (event) {
                        event.stopPropagation();
                        //event.preventDefault();
                    });

                    $('#insuranceBnftDialogConfirm').on('hidden.bs.modal', function (e) {
                        Android.isModelShow(false);
                    })
                    $('#insuranceBnftDialogConfirm').on('shown.bs.modal', function (e) {
                        Android.isModelShow(true);
                    })

                }
				
                // Viewer 缩略图点击事件
                function viewClick(viewerid) {
                    var viewerId = viewerid;
                    var viewer = GLOBAL_PARAM.ViewerMap.get(viewerId);
                    $("#myModalLabel").html(viewer.cName);
                    $("#hidViewerId").val(viewerId);
                    $("#myModalBody").html(viewer.doInitParam());
                    viewer.doInitEvent();
                    $('#myModal').modal();
                }
				$('#myModal').on('hidden.bs.modal', function (e) {
                    Android.isModelShow(false);
                })
                $('#myModal').on('shown.bs.modal', function (e) {
                    Android.isModelShow(true);
                })
				
				// Viewer 缩略图选择项点击事件
                function viewCheckBoxClick(viewerid) {
                    var viewerId = viewerid;
                    GLOBAL_PARAM.ViewerMap.get(viewerId).checkStatus = $("#" + viewerId).is(":checked") ? "1" : "0";
                }
				
				/*
                 * 收集选中的Viewer信息,手机端用
                 */
                function collectViewersInfo() {
                    var proConfig = {
                        "template": {
                            "id": "",
                            "name": "",
                            "version": "",
							"mode": "",
                            "defaultparam": {
                                "style": "",
                                "viewerver": ""
                            },
                            "viewers": null
                        }
                    }
                    proConfig.template.id = GLOBAL_PARAM.TemplateConfig.template.id;
                    proConfig.template.name = GLOBAL_PARAM.TemplateConfig.template.name;
                    proConfig.template.version = GLOBAL_PARAM.TemplateConfig.template.version;
                    proConfig.template.defaultparam = GLOBAL_PARAM.TemplateConfig.template.defaultparam;
					
					if (GLOBAL_PARAM.TemplateConfig.template.mode != null) {
                        proConfig.template.mode = GLOBAL_PARAM.TemplateConfig.template.mode;
                    }
					
                    var viewers = "[";
                    // 遍历所有要显示的Viewer
                    $(".viewcheckmark").each(function () {
                        if ($(this).is(":checked")) {
                            var viewid = $(this).attr("id");
                            var viewer = GLOBAL_PARAM.ViewerMap.get(viewid);
                            viewer.checkStatus = 1;
                            viewer.doAfterParam();
                            var viewerConfig = '{"fieldName":"' + viewer.fieldName + '","fromJson":' + viewer.toJson() + '},';
                            viewers += viewerConfig;
                        }
                    });
                    viewers += "]";
                    proConfig.template.viewers = eval(viewers);
                    $("#HidProposalConfig").val(convertJson2Str(proConfig));
                }
				
                /*
                 * 收集选中的Viewer信息,并输出这是Viewer内容
                 */
                function collectAndDisplayViewers() {
                    var proConfig = {
                        "template": {
                            "id": "",
                            "name": "",
                            "version": "",
							"mode": "",
                            "defaultparam": {
                                "style": "",
                                "viewerver": ""
                            },
                            "viewers": null
                        }
                    }
                    proConfig.template.id = GLOBAL_PARAM.TemplateConfig.template.id;
                    proConfig.template.name = GLOBAL_PARAM.TemplateConfig.template.name;
                    proConfig.template.version = GLOBAL_PARAM.TemplateConfig.template.version;
                    proConfig.template.defaultparam = GLOBAL_PARAM.TemplateConfig.template.defaultparam;

					if (GLOBAL_PARAM.TemplateConfig.template.mode != null) {
                        proConfig.template.mode = GLOBAL_PARAM.TemplateConfig.template.mode;
                    }
					
                    // 清空之前的内容
                    $(".viewcontainer").html("");
                    var viewers = "[";
                    var monitors = "[";
                    // 遍历所有要显示的Viewer
                    $(".viewcheckmark").each(function () {
                        if ($(this).is(":checked")) {
                            var viewid = $(this).attr("id");
                            var viewer = GLOBAL_PARAM.ViewerMap.get(viewid);
                            viewer.checkStatus = 1;
							viewer.doAfterParam();
                            var viewerConfig = '{"fieldName":"' + viewer.fieldName + '","fromJson":' + viewer.toJson() + '},';
                            viewers += viewerConfig;
                            viewer.doEndViewer();
							monitors += viewer.getMonitors();
							setViewerCheck(viewid,1);
                        } else {
                            var viewid = $(this).attr("id");
                            var viewer = GLOBAL_PARAM.ViewerMap.get(viewid);
                            viewer.checkStatus = 0;
							setViewerCheck(viewid,0);
                        }
                    });
                    if (GLOBAL_PARAM.TemplateConfig.template.tmpltdscrpt != null && GLOBAL_PARAM.TemplateConfig.template.tmpltdscrpt.length != 0) {
                        $("#tempdescript").remove();
                        $("#viewer_cont").append('<div id="tempdescript" class="row"><div class="col-xs-12 fnt_title">' + GLOBAL_PARAM.TemplateConfig.template.tmpltdscrpt + "</div></div>");
                    }
                    viewers += "]";
                    monitors = monitors.substring(0, monitors.length - 1) + "]";
                    proConfig.template.viewers = eval(viewers);
                    $("#HidProposalConfig").val(convertJson2Str(proConfig));
                    $("#HidTrackMonitors").val(monitors);
                }
				
				 /*
                 * 设置Viewer默认选中
                 */
                function setViewerCheck(viewid, status) {
                    var viewers = GLOBAL_PARAM.TemplateConfig.template.viewers;
                    for (var i = 0; i < viewers.length; i++) {
                        if (viewers[i].fieldName == viewid) {
                            viewers[i].check = status
                        }
                    }
                }

                /*
                 * 恢复之前选中设置的Viewer
                 */
                function recoverChosedViewer() {

                    var proViewers = convertStr2Json($("#HidProposalConfig").val()).template.viewers;

                    var prdctKeys = GLOBAL_PARAM.ProductMap.keys();
                    for (var i = 0; i < proViewers.length; i++) {
                        var viewConfig = proViewers[i];
                        var viewer = eval("new " + viewConfig.fieldName + "()");
                        if (viewConfig.fromJson != null) {
                            viewer.fromJson(viewConfig.fromJson);
                        }
                        // 给Viewer设置产品信息
                        for (var j = 0; j < prdctKeys.length; j++) {
                            viewer.addProduct(GLOBAL_PARAM.ProductMap.get(prdctKeys[j]));
                        }
                        viewer.doEndViewer();
                    }
                }

                /*
                 * 计算产品的保额保费
                 */
                function setCoverageAndPremium(inseObj) {
                    var newRate = inseObj.getRate();
                    var iCountMode = inseObj.getNodeByFieldName("CPCalculateMode").getEBTValue();
                    var unitValue;
                    var multipleMin;
                    var multipleMax;
                    var inputValue = 0;
                    var anotherField = "";
                    // 保额算保费
                    if (String(iCountMode).toLowerCase() == "true") {
                        // 单位值
                        unitValue = inseObj.getNodeByFieldName("CUnitValue").getEBTValue();
                        multipleMin = inseObj.getNodeByFieldName("CMultipleMin").getEBTValue();
                        multipleMax = inseObj.getNodeByFieldName("CMultipleMax").getEBTValue();
                        try {
                            var paramNode = inseObj.getNodeByFieldName("CoverageUseAnotherFieldName");
                            anotherField = paramNode.getEBTValue();
                        } catch (e) { }
                        if (anotherField == "") {
                            inputValue = inseObj.getCoverage();
                        } else {
                            var coverageNode = inseObj.getNodeByFieldName(anotherField);
                            inputValue = coverageNode.getEBTValue().getSelectedValue();
                        }
                    } else {
						inputValue = inseObj.getPremium();
                        unitValue = inseObj.getNodeByFieldName("PUnitValue").getEBTValue();
                        multipleMin = inseObj.getNodeByFieldName("PMultipleMin").getEBTValue();
                        multipleMax = inseObj.getNodeByFieldName("PMultipleMax").getEBTValue();
                    }
                    var minValue = unitValue * multipleMin;
                    var maxValue = unitValue * multipleMax;
                    if ((inputValue > maxValue && maxValue >0) || (inputValue < minValue && 0 <= minValue)) {  
                        //alert("设置项目的有效区间为：" + minValue + "～" + maxValue);
                        inputValue = minValue;
                    }
                    // 小数精度
                    var iDecimalDigits = inseObj.getNodeByFieldName("DecimalDigits").getEBTValue();
                    // 有保额替代字段时，保费直接为查找的费率表数据，无需再乘以保额
                    if (String(iCountMode).toLowerCase() == "true" && anotherField != "") {
                        inseObj.setPremium(Number(newRate).toFixed(iDecimalDigits));
                    } else {
                        if (inseObj.getIsSpecialProduct()) {
                            var countValue = 0;
                            rtbc = inseObj.getNodeByFieldName("RateTableBaseCoverage").getEBTValue();
                            if (inputValue > rtbc) {
                                countValue = eval(newRate)[0] + (inputValue - rtbc) / unitValue * eval(newRate)[1];
                            } else {
                                countValue = eval(newRate)[0];
                            }
                            countValue = Number(countValue).toFixed(iDecimalDigits);
                        } else {
                            countValue = Number(inputValue / unitValue * newRate).toFixed(iDecimalDigits);
                        }
                        if (String(iCountMode).toLowerCase() == "true") {
                            inseObj.setPremium(countValue);
                            inseObj.setCoverage(inputValue);
                        } else {
                            inseObj.setCoverage(countValue);
                            inseObj.setPremium(inputValue);
                        }
                    }
                }
						
               
            </script>
        </div>

    </form>
    <script type="text/javascript">
	　
		 
         /*
          * 获取方案配置信息
          */
         function getProposalConfig() {
             Android.getProposalConfig($("#HidProposalConfig").val());
         }
         
         function getSendHtml() {
            try {
                collectAndDisplayViewers();

                $("#proposalContainer").show();

                var viewer = GLOBAL_PARAM.ViewerMap.get('VCoverSubjectXH');
                if (viewer === undefined) {
                    viewer = GLOBAL_PARAM.ViewerMap.get('VCoverSubjectV2');
                }
                var strResult = viewer.getCoverBg();

                $("#HidParams").remove();
                $("#viewcontainer").remove();
                $("#jsscript").remove();

				var strSaveHtml = $("html").html();
				
				//附件View 服务器地址替换本地地址
                localReplaceToUrl();
				
                $("img[picPath]").each(function () {
                    $(this).attr("src", $(this).attr("picPath")).removeAttr("picPath");
                });
				$('body').css("background-color", "#d4d4d4");
                $('#viewer_cont').css({ "background": "#fff"});
                Android.getSendHtml(strSaveHtml,$("html").html(), strResult);
            }
            catch (e) {
                Android.getExceptionInfo("选择的产品正在维护中,请选择其它产品");
            }
        }
		
		// 手机方案预览
        function getConfigInfo() {
            try {
              
                collectViewersInfo();

                var viewers = GLOBAL_PARAM.TemplateConfig.template.viewers;
                var result = '{\\\"template\\\":{\\\"id\\\":\\\"123\\\",\\\"name\\\":\\\"寿险模板\\\",\\\"tmpltdscrpt\\\":\\\"<b>本方案仅供参考，具体权利义务请以正式保险合同为准。</b><p><b>本方案由宜保通自动生成，<a href=\\\\\\"http://m.e-baotong.cn\\\\\\"target=\\\\\\"_blank\\\\\\">去了解宜保通？</a></b></p>\\\",\\\"version\\\":\\\"1.0\\\",\\\"defaultparam\\\":{\\\"style\\\":\\\"123\\\",\\\"viewerver\\\":\\\"1.0\\\"},\\\"viewers\\\":' + convertJson2Str(viewers).replace(/"/g, '\\\"') + '}}';

                Android.getConfigInfo($("#HidProposalConfig").val(), result);

            }
            catch (e) {
                Android.getExceptionInfo("选择的产品正在维护中,请选择其它产品");
            }
        }
		
        // 方案预览按钮
        function getPreviewHtml() {
            try {
                $("#viewcontainer").hide();
                $("#proposalContainer").show();
                collectAndDisplayViewers();

                Android.getPreviewHtml($("html").html());
                $("#viewcontainer").show();
                $("#proposalContainer").hide();
            }
            catch (e) {
                $("#viewcontainer").show();
                $("#proposalContainer").hide();
                Android.getExceptionInfo("选择的产品正在维护中,请选择其它产品");
            }
        }

        setInterval(function () { $(".glyphicon-hand-right").fadeOut(200).fadeIn(200); }, 1400);
        
        function productView(productID) {
            if ($("#HidTrackProposalId").val() == "") {
			    Android.isPreview(true);
                return;
            }
            window.open('http://p.yibaoyun.cn/ASP/PlanView.aspx?prpslid=' + $("#HidTrackProposalId").val() + '&prdctid=' + $(productID).attr("productID") + '&indx=' + $(productID).attr("productIndex"));
        }

		
	var MAX_IMAGE_COUNT = 3;
        var MAX_FILE_COUNT = 1;
        
	// 附件上传callback
        var Attachment_List = new Array();
        var Attachment_ListCount = 0;
        var imgCount = 0;
        var fileCount = 0;
        function setAttachFilesJSON(json) {

            var successAttachCount = 0;
		//保存UUID
            var arrdbUuuid = new Array();
            if ($('#HidAttatchUuid').val() != "") {
                arrdbUuuid = eval($('#HidAttatchUuid').val());
            }
            
            //传入json转化为数组
            var attResultAttach = new Array();
            var attResultAttachFinal = new Array();
            attResultAttach = eval(json);

            //检查是否有历史json
            if ($('#HidAttatchJson').val() != "") {
                Attachment_List = eval($('#HidAttatchJson').val());
            }

            //json数组构建id
            for (var i = 0; i < attResultAttach.length; i++) {
                attResultAttach[i].id = Attachment_ListCount + i;
            }

            //更新本次附件List
            for (var i = 0; i < attResultAttach.length; i++) {
                var name = attResultAttach[i].name;
                var desciption = attResultAttach[i].desciption == undefined ? "" : attResultAttach[i].desciption;
                var local = attResultAttach[i].local;
                var index = attResultAttach[i].id;
                var url = attResultAttach[i].url;
                var dbUuuid = attResultAttach[i].dbUuuid;

                //文件类型
                var fileExtension = local.substring(local.lastIndexOf('.') + 1).toUpperCase();
                var imgHtml = ""
                var vlCheck = true;
                var vlCheckMsg = ""

                switch (fileExtension) {
                    //图片
                    case "JPG": case "JPEG": case "GIF": case "PNG":
                        imgCount++;
                        if (imgCount > MAX_IMAGE_COUNT) {
                            imgCount--;
                            vlCheck = false;
                            vlCheckMsg = "抱歉，您能添加的图片数量已至上限。";
                        }
                        imgHtml = '<img class="media-object" data-src="holder.js/64x64" alt="64x64" src="' + local + '" data-holder-rendered="true" style="width: 64px; height: 64px;">';
                        break;
                    //视频
                    case "MP4":
                        fileCount++;
                        if (fileCount > MAX_FILE_COUNT) {
                            fileCount--;
                            vlCheck = false;
                            vlCheckMsg = "抱歉，您能添加的文件数量已至上限。"
                        }
                        imgHtml = '<img class="media-object" data-src="holder.js/64x64" alt="64x64" src="" data-holder-rendered="true" style="width: 64px; height: 64px; background-color:#002d8a; ">';
                        break;
                    //音频
                    case "MP3": 
                        fileCount++;
                        if (fileCount > MAX_FILE_COUNT) {
                            fileCount--;
                            vlCheck = false;
                            vlCheckMsg = "抱歉，您能添加的文件数量已至上限。"
                        }
                        imgHtml = '<img class="media-object" data-src="holder.js/64x64" alt="64x64" src="" data-holder-rendered="true" style="width: 64px; height: 64px;background-color:#653ebf; ">';
                        break;
                    //Word
                    case "DOC": case "DOCX": case "TXT":
                        fileCount++;
                        if (fileCount > MAX_FILE_COUNT) {
                            fileCount--;
                            vlCheck = false;
                            vlCheckMsg = "抱歉，您能添加的文件数量已至上限。"
                        }
                        imgHtml = '<img class="media-object" data-src="holder.js/64x64" alt="64x64" src="" data-holder-rendered="true" style="width: 64px; height: 64px;background-color:#2f93e8; ">';
                        break;
                    //Excel
                    case "XLS": case "XLSX":
                        fileCount++;
                        if (fileCount > MAX_FILE_COUNT) {
                        	  fileCount--;
                            vlCheck = false;
                            vlCheckMsg = "抱歉，您能添加的文件数量已至上限。";
                        }
                        imgHtml = '<img class="media-object" data-src="holder.js/64x64" alt="64x64" src="" data-holder-rendered="true" style="width: 64px; height: 64px;background-color:#00a51b; ">';
                        break;
                    //ppt
                    case "PPT": case "PPTX":
                        fileCount++;
                        if (fileCount > MAX_FILE_COUNT) {
                            fileCount--;
                            vlCheck = false;
                            vlCheckMsg = "抱歉，您能添加的文件数量已至上限。"
                        }
                        imgHtml = '<img class="media-object" data-src="holder.js/64x64" alt="64x64" src="" data-holder-rendered="true" style="width: 64px; height: 64px;background-color:#e87731; ">';
                        break;
                    //PDF
                    case "PDF":
                        fileCount++;
                        if (fileCount > MAX_FILE_COUNT) {
                            fileCount--;
                            vlCheck = false;
                            vlCheckMsg = "抱歉，您能添加的文件数量已至上限。";
                        }
                        imgHtml = '<img class="media-object" data-src="holder.js/64x64" alt="64x64" src="" data-holder-rendered="true" style="width: 64px; height: 64px;background-color:#be1d49; ">';
                        break;
                    //Web
                    case "HTML":
                        fileCount++;
                        if (fileCount > MAX_FILE_COUNT) {
                            fileCount--;
                            vlCheck = false;
                            vlCheckMsg = "抱歉，您能添加的文件数量已至上限。";
                        }
                        imgHtml = '<img class="media-object" data-src="holder.js/64x64" alt="64x64" src="" data-holder-rendered="true" style="width: 64px; height: 64px;background-color:#e39f18; ">';
                        break;
                    //其他
                    default:
                        fileCount++;
                        if (fileCount > MAX_FILE_COUNT) {
                            fileCount--;
                            vlCheck = false;
                            vlCheckMsg = "抱歉，您能添加的文件数量已至上限。"
                        }
                        imgHtml = '<img class="media-object" data-src="holder.js/64x64" alt="64x64" src="" data-holder-rendered="true" style="width: 64px; height: 64px;background-color:#404040; ">';
                        break;
                }

               //数量check（图片3个，其他1个）
                if (!vlCheck && fileCount >= MAX_FILE_COUNT && imgCount >= MAX_IMAGE_COUNT) {
                    $(".VAttachment-Add").attr("disabled", "disabled");
                    $(".VAttachment-Msg").text("抱歉，您能添加的文件和图片数量已至上限。");
                    Android.showToast("抱歉，您能添加的文件和图片数量已至上限。")
                    continue;
                }
                if (!vlCheck) {
                    $(".VAttachment-Msg").html('可添加的图片数量（<span style="color:blue;font-size:18px">' + imgCount + '</span>/' + MAX_IMAGE_COUNT + '）,可添加的其他文件数量（<span style="color:blue;font-size:18px">' + fileCount + '</span>/' + MAX_FILE_COUNT + '）');
                    if (imgCount == MAX_IMAGE_COUNT) {
                        Android.showToast("抱歉，您可添加的图片数量已至上限。")
                    }
                    else if (fileCount == MAX_FILE_COUNT) {
                        Android.showToast("抱歉，您可添加的其他文件数量已至上限。")
                    }
                    continue;
                }

                $(".VAttachment-Msg").html('可添加的图片数量（<span style="color:blue;font-size:18px">' + imgCount + '</span>/' + MAX_IMAGE_COUNT + '）,可添加的其他文件数量（<span style="color:blue;font-size:18px">' + fileCount + '</span>/' + MAX_FILE_COUNT + '）');

                successAttachCount++;

                //更新参数画面
                var $attachment_rowd = $('<div class="row attachMark" id="Mark' + index + '" style="margin:20px">' +
                                             '<div class="col-xs-2">' +
                                                        imgHtml +
                                               '</div>' +
                                               '<div class="col-xs-7">' +
                                                       '<h4 class="media-heading"><input type="text" readonly class="inputMark inputReadonly" value="' + name + '"></h4>' +
                                                       '<textarea class="form-control inputAreaMark inputAreaReadonly " rows="2" readonly>' + desciption + '</textarea>' +
                                               '</div>' +
                                               '<div class="col-xs-3">' +
                                                   '<button type="button" class="btn VAttachment-Edit" onclick="updateMain($(this))" updateFlag="1" style="margin-bottom: 5px;margin-right: 5px;background-color: #eee;    border: 1px solid #999999;"><span class="glyphicon glyphicon glyphicon-pencil" aria-hidden="true" style="color:#999999"></span></button><button type="button" class="btn VAttachment-Del" onclick="deleteMain($(this))" style="margin-bottom: 5px;margin-right: 5px;background-color: #eee; border: 1px solid #999999;"><span class="glyphicon  glyphicon-trash" aria-hidden="true" style="color:#999999"></span></button>' +
                                               '</div>' +
                                           '</div>');

                $('#attachment').append($attachment_rowd);
		    arrdbUuuid.push(dbUuuid);
                attResultAttachFinal.push(attResultAttach[i]);
                
                //数量check（图片3个，其他1个）
                if (fileCount >= MAX_FILE_COUNT && imgCount >= MAX_IMAGE_COUNT) {
                    $(".VAttachment-Add").attr("disabled", "disabled");
                    $(".VAttachment-Msg").text("抱歉，您能添加的文件和图片数量已至上限。");
                    continue;
                }
            }

            //维护全局附件列表
            Attachment_ListCount = Attachment_ListCount + successAttachCount;
            Array.prototype.push.apply(Attachment_List, attResultAttachFinal);
            $('#HidAttatchJson').val(JSON.stringify(Attachment_List));
            $('#HidAttatchUuid').val(JSON.stringify(arrdbUuuid));
        }
        //附件View删除按钮方法
        function deleteMain(obj) {
            var arrAttachment = eval($('#HidAttatchJson').val())
            var index = parseInt(obj.parent().parent().attr("id").replace("Mark", ""));
            for (var i = 0; i < arrAttachment.length; i++) {
                if (arrAttachment[i].id == index) {
                    var fileExtension = arrAttachment[i].local.substring(arrAttachment[i].local.lastIndexOf('.') + 1).toUpperCase();
                    arrAttachment.splice(i, 1);
                }
            }

            switch (fileExtension) {
                case "JPG": case "JPEG": case "GIF": case "PNG":
                    imgCount--;
                    imgCount = imgCount < 0 ? 0 : imgCount;
                    $(".VAttachment-Msg").html('可添加的图片数量（<span style="color:blue;font-size:18px">' + imgCount + '</span>/' + MAX_IMAGE_COUNT + '）,可添加的其他文件数量（<span style="color:blue;font-size:18px">' + fileCount + '</span>/' + MAX_FILE_COUNT + '）');
                    $(".VAttachment-Add").removeAttr("disabled");
                    break;
                default:
                    fileCount--;
                    fileCount = fileCount < 0 ? 0 : fileCount;
                    $(".VAttachment-Msg").html('可添加的图片数量（<span style="color:blue;font-size:18px">' + imgCount + '</span>/' + MAX_IMAGE_COUNT + '）,可添加的其他文件数量（<span style="color:blue;font-size:18px">' + fileCount + '</span>/' + MAX_FILE_COUNT + '）');
                    $(".VAttachment-Add").removeAttr("disabled");
                    break;
            }


            $('#HidAttatchJson').val(JSON.stringify(arrAttachment))
            obj.parent().parent(".attachMark").remove();
            
             //更新Uuid
            var arrUuid = new Array();
            for (var i = 0; i < arrAttachment.length; i++) {
                arrUuid.push(arrAttachment[i].dbUuuid)
            }
            $('#HidAttatchUuid').val(JSON.stringify(arrUuid));
        }
        
        //附件View编辑按钮方法
        function updateMain(obj) {
            //编辑
            if (obj.attr("updateFlag") == "1") {
                var spanchild = obj.children(".glyphicon");
                spanchild.removeClass("glyphicon-pencil");
                spanchild.addClass("glyphicon-ok");

                var name = obj.parent().prev().find(".inputMark");
                name.removeAttr("readonly");
                name.removeClass("inputReadonly");
                var nameArea = obj.parent().prev().find(".inputAreaMark");
                nameArea.removeAttr("readonly");
                nameArea.removeClass("inputAreaReadonly");
                obj.attr("updateFlag","2")
            } else {
                //完成
                var name = obj.parent().prev().find(".inputMark");
                var spanchild = obj.children(".glyphicon");
                spanchild.removeClass("glyphicon-ok");
                spanchild.addClass("glyphicon-pencil");

                name.attr("readonly", "");
                name.addClass("inputReadonly");
                var nameArea = obj.parent().prev().find(".inputAreaMark");
                nameArea.attr("readonly","");
                nameArea.addClass("inputAreaReadonly");
                obj.attr("updateFlag","1")

                //保存数据
                var arrAttachment = eval($('#HidAttatchJson').val())
                var index = parseInt(obj.parent().parent().attr("id").replace("Mark", ""));
                for (var i = 0; i < arrAttachment.length; i++) {
                    if (arrAttachment[i].id == index) {
                        arrAttachment[i].name = name.val();
                        arrAttachment[i].desciption = nameArea.val();
                    }
                }
                $('#HidAttatchJson').val(JSON.stringify(arrAttachment))
            }
        }     
        
        //附件View 服务器地址替换本地地址
        function localReplaceToUrl() {
            $('.mediaMark').each(function () {
                var url = $(this).attr("urlMark");
                $(this).attr("src", url)
            });

            $('.linkMark').each(function () {
                var url = $(this).attr("urlMark");
                $(this).attr("href", url)
            })
        }
        
        // 方案图表重绘
        function highchartsReflow() {
		
		     //添加区间事件
            $(".btnchart-lazyload").click(function () {
                var modelDataTarget = $(this).attr("data-target");
                $(modelDataTarget).on('shown.bs.modal', function (e) {

                    var highchartObj = $(modelDataTarget).find(".highchartsArea-lazyload");
                        var chartJs = highchartObj.attr('chartJs');
                        var chartData = highchartObj.attr('chartData');
                        if (chartJs != '') {
                            highchartObj.highcharts(JSON.parse(chartJs));
                        }
                });
            });
			
            $('.highchartsArea').each(function () {
                var chartJs = $(this).attr('chartJs');
                var chartData = $(this).attr('chartData');
                 if (chartJs != '') {
                    $(this).highcharts(JSON.parse(chartJs));
                }
            });
          
			
			// 产品参数对比
            $(".table-btn-mark").click(function () {
                
                var insuredID = $(this).attr('insuredId');
                $('.btn-group-mark').each(function () {
                    $(this).css('display', 'none');
                })
                $('#btngroup' + insuredID).css('display', 'block');
                var modelDataTarget = $(this).attr("data-target");
                $(modelDataTarget).on('shown.bs.modal', function (e) {
                    $('#containerDiff').highcharts({
                        title: { text: "利益比较" },
                        xAxis: {
                            labels: {
                                format: '{value} 岁'
                            }
                        },
                        yAxis: {
                            floor: 0,
                            title: {
                                text: '保险金额（元）'
                            },
                            labels: {
                                format: '{value} 元'
                            }
                        },
                        tooltip: {
                            pointFormat: '{series.name} <b>{point.y:,.2f}元</b><br/>年龄 {point.x}周岁'
                        },
                        plotOptions: {
                            series: {
                                marker: {
                                    enabled: false
                                },
                            }
                        },
                        series: []
                    });
                    $('#btngroup' + insuredID + ' input:first').click();
                    $('#btngroup' + insuredID + ' input:first').focus();
                });
            });

            $(".model-btn-chart").click(function () {
                var data = JSON.parse($(this).attr('chartdata'));
                $('#containerDiff').highcharts({
                    xAxis: {
                        labels: {
                            format: '{value} 岁'
                        }
                    },
                    yAxis: {
                        floor: 0,
                        title: {
                            text: '保险金额（元）'
                        },
                        labels: {
                            format: '{value} 元'
                        }
                    },
                    tooltip: {
                        pointFormat: '{series.name} <b>{point.y:,.2f}元</b><br/>年龄 {point.x}周岁'
                    },
                    title: {
                        text: $(this).attr('value'),
                    },
                    plotOptions: {
                        series: {
                            marker: {
                                enabled: false
                            },
                        }
                    },
                    series: data
                });
            });
			
			// 滚动条------------------------------------------------------------------------------------------------------------------------------
            var BarB = $(".bar_bg"),
                BarC = $(".bar_click"),
                BarP = $(".bar_percent"),
                BarI = $(".bar_input"),
                BarBW,
                BarCMove = false,
                BarCX,
                BarMoveObject,
                BarPMoveObject,
                BarIMoveObject;
            BarC.mousedown(function (e) {
                BarCMove = true;
                var BarBX = parseInt($(this).css("left"));
                BarCX = e.pageX - BarBX;
                BarMoveObject = $(this);
                BarPMoveObject = $(this).next()
                BarBW = $(this).parent().width();
                BarIMoveObject = $(this).children();
            });
            $(document).mousemove(function (e) {
                if (BarCMove) {
                    var PageX = e.pageX;
                    var CX = PageX - BarCX;
                    if (CX <= 0) {
                        CX = 0
                    } else if (CX >= BarBW) {
                        CX = BarBW
                    } else {
                        CX = PageX - BarCX;
                    };
                    BarMoveObject.css({ "left": CX });
                    BarPMoveObject.css({ "width": parseInt(CX / BarBW * 100) + "%" });
					chart = BarPMoveObject.parent().parent().prevAll(".highchartsArea-lazyload").highcharts();
                    // 取得利益表行数
                    var maxAge = BarMoveObject.attr("maxAge");
                    var minAge = BarMoveObject.attr("minAge");
                    var rowCount = maxAge - minAge;

                    // 取得水平滚动比例
                    var horizontalRatio = BarBW / rowCount;
                    var age = (parseInt(minAge)) + (parseInt(CX / horizontalRatio) == 0 ? 0 : parseInt(CX / horizontalRatio));
                    if (age == minAge) {
                        BarIMoveObject.text("首年")
                    } else if (age == maxAge) {
                        BarIMoveObject.text("期满")
                    } else {
                        BarIMoveObject.text(age + "岁");
                    }
                    var chartData = BarMoveObject.parent().parent().attr('chartData');
                    var areaSourceData = JSON.parse(chartData);
                    var arrData = new Array();
                    var selYear = age;
                    for (var j = 0; j < areaSourceData.length; j++) {
                        var data = areaSourceData[j].data;
                        var name = areaSourceData[j].name;
                        for (var k = 0; k < data.length; k++) {
                            if (data[k][0] == selYear) {
                                arrData.push({ name: name, data: [parseFloat(data[k][1].toFixed(2))] });
                                break;
                            }
                        }
                    }
                    for (var j = 0; j < arrData.length; j++) {
                        for (var k = 0; k < areaSourceData.length; k++) {
                            if (areaSourceData[k].name == arrData[j].name) {
                                chart = BarMoveObject.parent().parent().prevAll(".highchartsArea-lazyload").highcharts();
                                chart.series[k].setData(arrData[j].data);
                                chart.xAxis[0].categories[0] = BarIMoveObject.text();
                                break;
                            }
                        }
                    }
                }
            }).mouseup(function () {
                BarCMove = false;
            });

            // Touch事件
            var BarBTouch = $(".bar_bg"),
		        BarCTouch = $(".bar_click"),
		        BarPTouch = $(".bar_percent"),
		        BarITouch = $(".bar_input"),
		        BarTouchBW,
		        BarCMoveTouch = false,
		        BarCXTouch,
                BarTouchMoveObject,
                BarPTouchMoveObject,
                BarITouchMoveObject;

            var x = document.getElementsByClassName('bar_click');
            var i;
            for (i = 0; i < x.length; i++) {
                x[i].addEventListener('touchstart', function (event) {
                    BarCMoveTouch = true;
                    var BarBX = parseInt($(this).css("left"));
                    BarCXTouch = event.touches[0].clientX - BarBX;
                    BarTouchMoveObject = $(this);
                    BarPTouchMoveObject = $(this).next();
                    BarTouchBW = $(this).parent().width();
                    BarITouchMoveObject = $(this).children();
                }, false);

                x[i].addEventListener('touchmove', function (event) {
				　　event.preventDefault();
                    event.stopImmediatePropagation();
                    if (BarCMoveTouch) {
                        var touch = event.targetTouches[0];
                        var PageX = touch.pageX;
                        var CX = PageX - BarCXTouch;
                        if (CX <= 0) {
                            CX = 0
                        } else if (CX >= BarTouchBW) {
                            CX = BarTouchBW
                        } else {
                            CX = PageX - BarCXTouch;
                        };
                        BarTouchMoveObject.css({ "left": CX });
                        BarPTouchMoveObject.css({ "width": parseInt(CX / BarTouchBW * 100) + "%" });

                        // 取得利益表行数
                        var maxAge = BarTouchMoveObject.attr("maxAge");
                        var minAge = BarTouchMoveObject.attr("minAge");
                        var rowCount = maxAge - minAge;

                        // 取得水平滚动比例
                        var horizontalRatio = BarTouchBW / rowCount;
                        var age = (parseInt(minAge)) + (parseInt(CX / horizontalRatio) == 0 ? 0 : parseInt(CX / horizontalRatio));
                        BarITouchMoveObject.attr("valueAge", age);
                        if (age == minAge) {
                            BarITouchMoveObject.text("首年")
                        } else if (age == maxAge) {
                            BarITouchMoveObject.text("期满")
                        } else {
                            BarITouchMoveObject.text(age + "岁");
                        }
                    }
                }, false);

                x[i].addEventListener('touchend', function (event) {
                    BarCMoveTouch = false;

                    chart = BarPTouchMoveObject.parent().parent().prevAll(".highchartsArea-lazyload").highcharts();
                    var chartData = BarTouchMoveObject.parent().parent().attr('chartData');
                    var areaSourceData = JSON.parse(chartData);
                    var arrData = new Array();
                    var selYear = $(this).children().attr("valueAge");
                    for (var j = 0; j < areaSourceData.length; j++) {
                        var data = areaSourceData[j].data;
                        var name = areaSourceData[j].name;
                        for (var k = 0; k < data.length; k++) {
                            if (data[k][0] == selYear) {
                                arrData.push({ name: name, data: [parseFloat(data[k][1].toFixed(2))] });
                                break;
                            }
                        }
                    }
                    for (var j = 0; j < arrData.length; j++) {
                        for (var k = 0; k < areaSourceData.length; k++) {
                            if (areaSourceData[k].name == arrData[j].name) {
                                chart.series[k].setData(arrData[j].data);
                                chart.xAxis[0].categories[0] = BarITouchMoveObject.text();
                                break;
                            }
                        }
                    }
                }, false);
            }

            //初始化
            touchMoveInitialize();
            // 滚动条------------------------------------------------------------------------------------------------------------------------------
        }
        
        $(document).ready(function () { 
					
         //LengentHandelMap = new Map();
        //Highcharts.setOptions({
        //    chart: {
        //        events: {
        //            load: function () {
        //                autoPlay(this, this.container.id);
        //            }, click: function (e) {
        //                var name = this.container.id;
        //                if (LengentHandelMap.get(name) > 0) {
        //                    clearInterval(LengentHandelMap.get(name));
        //                    LengentHandelMap.remove(name);
        //                } else {
        //                    autoPlay(this, this.container.id);
        //                }
        //            }
        //        }
        //    },
        //    plotOptions: {
        //        series: {
        //            events: {
        //                legendItemClick: function (event) {
        //                    var index = this.index;
        //                    var series = this.chart.series;
        //                    if (!series[index].visible) {
        //                        for (var i = 0; i < series.length; i++) {
        //                            var s = series[i];
        //                            i === index ? s.show() : s.hide();
        //                        }
        //                    }
        //                    return false;
        //                }
        //            }
        //        }
        //    }
        //});

		   
				
            highchartsReflow();
        });
		
		 function autoPlay(c, name) {
            var series = c.series;
            var seriesLength = c.series.length;
            var index = 0;
            var nameHandel = setInterval(function () {
                if (index === seriesLength) index = 0;
                for (var i = 0; i < seriesLength; i++) {
                    var s = series[i];

                    if (i === index) s.show();
                    else s.hide();
                }
                index++;
            }, 2000);
            LengentHandelMap.put(name, nameHandel);
        }
		
		 window.onresize = function () {
            //初始化
            touchMoveInitialize()
        }
		
		 function touchMoveInitialize() {
            //初始化
            var BarBTouch = $(".bar_bg"),
		        BarCTouch = $(".bar_click"),
		        BarPTouch = $(".bar_percent"),
		        BarITouch = $(".bar_input"),
		        BarTouchBW,
		        BarCMoveTouch = false,
                BarTouchMoveObject,
                BarPTouchMoveObject,
                BarITouchMoveObject;

            var x = $('.bar_click');
            x.each(function () {

                BarCMoveTouch = true;
                var BarBX = parseInt(100);
                BarTouchMoveObject = $(this);
                BarPTouchMoveObject = $(this).next();
                BarTouchBW = $(this).parent().width();
                BarITouchMoveObject = $(this).children();

                var CX = 0;
                BarTouchMoveObject.css({ "left": CX });
                BarPTouchMoveObject.css({ "width": parseInt(CX / BarTouchBW * 100) + "%" });
                // 取得利益表行数
                var maxAge = BarTouchMoveObject.attr("maxAge");
                var minAge = BarTouchMoveObject.attr("minAge");
                var rowCount = maxAge - minAge;
                // 取得水平滚动比例
                var horizontalRatio = BarTouchBW / rowCount;
                 var age = minAge;
                BarITouchMoveObject.attr("valueAge", age);
                if (age == minAge) {
                    BarITouchMoveObject.text("首年")
                } else if (age == maxAge) {
                    BarITouchMoveObject.text("期满")
                } else {
                    BarITouchMoveObject.text(age + "岁");
                }

            });
        }
		
    </script>
    <script id="shareArea"></script>
</body>
</html>
